package com.example.contestsystem.Dao;

import com.example.contestsystem.Entity.JoinTeam;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;

import java.util.List;

public interface JoinTeamRepository extends JpaRepository<JoinTeam, Integer> {
    /*
      此接口访问表JoinTeam，通过学生账号StuAccount找到学生加入的队伍
      应用场景：
      1.在某个比赛页面显示当前登录的学生加入的队伍
      2.加入队伍 save
      3.退出队伍 delete
     */

    /**
     * 此方法通过学生账号找到团队id
     * 实际上没有实用的应用场景
     *
     * @return
     */
    List<JoinTeam> findByStuAccount(int stuAccount);

    JoinTeam findByTeamIdAndStuAccount(String teamId, int stuAccount);

    JoinTeam findByContestIdAndStuAccount(String contestId, int stuAccount);


    @Modifying
    @Transactional
    void deleteByTeamIdAndStuAccount(String teamId, int stuAccount);

    @Modifying
    @Transactional
    void deleteByContestIdAndStuAccount(String contestId, int stuAccount);

    @Modifying
    @Transactional
    void deleteByTeamId(String teamId);

    List<JoinTeam> findByTeamId(String teamId);

    @Modifying
    @Transactional
    void deleteByContestId(String contestId);
}
